package net.yxsoft.service.infrastructure;

import net.yxsoft.enumclass.LockEnumCls;
import net.yxsoft.model.infrastructure.TsDatamodelProperties;
import net.yxsoft.model.infrastructure.TsParty;
import net.yxsoft.model.infrastructure.TsUdmkey;
import rapid.core.Authuser;

import java.sql.Timestamp;
import java.util.List;

/**
 * @author Administrator
 */
public class UDMKeyService_oracle {
  /**
  * @MethodName: getDataModelUDMKeyChooseByParty
  * @Description:
  * @param: partyId
  * @return * @return java.util.List<net.yxsoft.model.infrastructure.TsDatamodelProperties>
  * @throws
  * @date 2023/8/31 13:33
  * @author wj
  */
  public static List<TsDatamodelProperties> getDataModelUDMKeyChooseByParty(String partyId) {

    TsParty _party = TsParty.dao.findById(partyId);


    String _state = LockEnumCls.LOCKED.getValue();

    if(_party != null){
      if("FN_FORM_DATA".equals(_party.getName())){
        _state = LockEnumCls.UNLOCKED.getValue();
      }
    }

    List<TsDatamodelProperties> _keys =
      TsDatamodelProperties.dao.find("SELECT * FROM TS_DATAMODEL_PROPERTIES " +
                                       "WHERE MODEL_ID=? AND ATTRIB_DESCN<>'''' AND STATE=?", partyId, _state);

    return _keys;
  }
  /**
  * @MethodName: saveUDMKey
  * @Description:
  * @param: partyName
   * @param: KeysValues
   * @param: KeysNames
   * @param: sessionUser
  * @return * @return int
  * @throws
  * @date 2023/8/31 13:34
  * @author wj
  */
  public static int saveUDMKey(String partyName, String KeysValues, String KeysNames, Authuser sessionUser) {
    Timestamp time = new Timestamp(System.currentTimeMillis());

    TsUdmkey _model = new TsUdmkey();

    _model.setAttrib01(partyName);
    _model.setAttrib02(KeysNames);
    _model.setAttrib20(KeysValues);

    _model.setCreated(time);
    _model.setCreatedBy(sessionUser.getId());
    _model.setLastUpd(time);
    _model.setLastUpdBy(sessionUser.getId());

    boolean _r = _model.save();
    if(_r) {
      //保存成功
      return 1;
    } else {
      //保存失败
      return -9;
    }
  }

  public static int removeUDMKey(String id) {
    boolean _r = new TsUdmkey().deleteById(id);
    if(_r) {
      //删除成功
      return 1;
    } else {
      //删除失败
      return -9;
    }

  }
}
